package com.ctosb.classviewer.clazz.attr;

import com.ctosb.classviewer.ClassReader;
import com.ctosb.classviewer.clazz.util.Attribute_infoParse;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Code_attribute extends Attribute_info {

    private short max_stack;
    private short max_locals;
    private int code_length;
    private byte code[];
    private short exception_table_length;
    private Exception_table exception_table[];
    private short attributes_count;
    private Attribute_info attributes[];

    @Override
    public void doParse(ClassReader classReader) {
        max_stack = classReader.readShort();
        max_locals = classReader.readShort();
        code_length = classReader.readInt();
        code = classReader.readBytes(code_length);
        exception_table_length = classReader.readShort();
        exception_table = new Exception_table[exception_table_length & 0xffff];
        for (int i = 0; i < exception_table.length; i++) {
            exception_table[i] = new Exception_table().parse(classReader, getClassFile());
        }
        attributes_count = classReader.readShort();
        attributes = Attribute_infoParse.parse(attributes_count, classReader, getClassFile());
    }

}
